from time import sleep
from turtle import title, setup, hideturtle, Pen, tracer, bgcolor, done
import write_txt, rose, cherry, trend
from sys import exit
import utils


def init():
    title("献给最爱的你❤")

    setup(utils.width, utils.height, 0, 0)
    hideturtle()


def penInit() -> object:
    newPen = Pen()
    newPen.hideturtle()
    return newPen


txtPen = penInit()
rosePen = penInit()
cherryPen = penInit()
trendPen = penInit()


def main() -> int:
    try:
        # 初始化
        init()
        # 画玫瑰
        rs = rose.Rose(rosePen)
        while True:
            if rs.drawRose():
                sleep(3)
                break
        rosePen.clear()
        tracer(2, 0)
        # 更换背景
        bgcolor("wheat")
        # 画樱花树
        cy = cherry.Cherry(cherryPen)
        cy.tree(11, 100)
        # threading.Thread(target=cy.tree, args=(12, 100), daemon=True).start()
        # 画旋转爱心
        trd = trend.Trend(trendPen)
        # threading.Thread(target=trd.drawTrend, args=(300, ), daemon=True).start()
        trd.drawTrend(300)
        # # 打印文字
        wt = write_txt.WriteTxt(txtPen)
        # threading.Thread(target=wt.writeTxt, args=(100, ), daemon=True).start()
        wt.writeTxt()

        done()
    except KeyboardInterrupt:
        return 1
    else:
        return 0
    finally:
        exit(0)


if __name__ == "__main__":
    exit(main())
